/**
 * @author 鍚存倍
 * @since 2022/10/13
 * 12:57
 */
package com.windgo.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.windgo.bean.MarketCollect;
import com.windgo.bean.MarketCollectExample;
import com.windgo.bean.MarketFootprint;
import com.windgo.bean.MarketFootprintExample;
import com.windgo.bean.common.BasePageInfo;
import com.windgo.bean.common.CommonData;
import com.windgo.mapper.MarketFootprintMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FootprintServiceImpl implements FootprintService{
      @Autowired
    MarketFootprintMapper marketFootprintMapper;

    @Override
    public CommonData<MarketFootprint> list(BasePageInfo basePageInfo, Integer id) {
        PageHelper.startPage(basePageInfo.getPage(), basePageInfo.getLimit());
        MarketFootprintExample marketFootprintExample= new MarketFootprintExample();
        marketFootprintExample.setOrderByClause(basePageInfo.getSort()+" "+basePageInfo.getOrder());
        MarketFootprintExample.Criteria criteria = marketFootprintExample.createCriteria();
        if(id!=null){
            criteria.andIdEqualTo(id);
        }
        List<MarketFootprint> list = marketFootprintMapper.selectByExample(marketFootprintExample);
        PageInfo<MarketFootprint> data = new PageInfo<>(list);
        return CommonData.data(data);
    }

    @Override
    public CommonData<MarketFootprint> search(BasePageInfo basePageInfo, Integer userId, Integer goodsId) {
        PageHelper.startPage(basePageInfo.getPage(), basePageInfo.getLimit());
        MarketFootprintExample marketFootprintExample = new MarketFootprintExample();
        marketFootprintExample.setOrderByClause(basePageInfo.getSort()+" "+basePageInfo.getOrder());
        MarketFootprintExample.Criteria criteria = marketFootprintExample.createCriteria();
        if(userId!=null){
            criteria.andUserIdEqualTo(userId);
        }
        if(goodsId!=null){
            criteria.andGoodsIdEqualTo(goodsId);
        }
        List<MarketFootprint> list = marketFootprintMapper.selectByExample(marketFootprintExample);
        PageInfo<MarketFootprint> data = new PageInfo<>(list);
        return CommonData.data(data);
    }
}

